﻿using System.Linq;
using WickedFlame.Core;
using WickedFlame.Core.History;
using WickedFlame.Core.Shapes;

namespace WickedFlame.Util.Actions
{
	/// <summary>
	/// Converts all selected shapes to polygon shapes
	/// </summary>
    public class ConvertShapeToPolygonAction
    {
        public void DoAction(DrawingCanvas canvas)
        {
			var shapes = (from s in canvas.SelectedLayer.ShapeList.Selection where s is IPolygonShape select s).ToList();

            foreach (VectorShape s in shapes)
            {
                var polygon = ((IPolygonShape)s).CreatePolygon();
                canvas.SelectedLayer.Replace(s, polygon);

                canvas.PushHistoryCommand(new ConvertToPolygonCommand(s, polygon, canvas.SelectedLayerIndex));
            }

			DrawingCanvas.DrawTrackers();
        }
    }
}
